$(document).ready(function() {
	if(cursex==0){
		$(".femal").hide();
		}else{
		$(".femal").show();
		}
	$.ajax({
         url: basePath+"diseaseHistory/toEditHis.spring",
         type: "POST",
         data:{id:id},
         dataType: 'json',
         cache: false,
         success: function (ret) {
         console.log(ret);
             if(ret!=null){
             	if(ret.list!=null&&ret.list.length>0){
             		var data=ret.list[0];
             		$("#historyName").text(data.historyName);
             		//既往史开始
             		$("#bodyHealth").val(data.bodyHealth);
//             		$("#bodyWeak").val(data.bodyWeak);
             		$("#wasSickSel").val(data.wasSick.substring(0,1));
             		if(data.wasSick.substring(0,1)=='0'){
             			$("#wasSick").hide();
             		}else{
             			$("#wasSick").show();
             			$("#wasSick").val(data.wasSick.substring(1,data.wasSick.length));
             		}
             		$("#operationSel").val(data.majorTrauma.substring(0,1));
             		if(data.majorTrauma.substring(0,1)=='0'){
             			$("#majorTrauma").hide();
             		}else{
             			$("#majorTrauma").val(data.majorTrauma.substring(1,data.majorTrauma.length));	
             		}
             		//手術
             		$("#operationSel").val(data.operation.substring(0,1));
             		if(data.operation.substring(0,1)=='0'){
             			$("#operation").hide();
             		}else{
             			$("#operation").val(data.operation.substring(1,data.operation.length));	
             		}
             		//过敏
             		$("#allergySel").val(data.allergy.substring(0,1));
             		if(data.allergy.substring(0,1)=='0'){
             			$("#allergy").hide();
             		}else{
             			$("#allergy").val(data.allergy.substring(1,data.allergy.length));	
             		}
             		$("#timelyVaccination").val(data.timelyVaccination);
             		$("#transfusion").val(data.transfusion);
             		//婚育史开始
             		$("#marriage").val(data.marriage);
             		$("#menophania").val(data.menophania);
             		$("#continueTime").val(data.continueTime);
             		$("#intervalTime").val(data.intervalTime);
             		$("#pausimenia").val(data.pausimenia);
             		$("#endMeniaTime").val(data.endMeniaTime);
             		$("#pregnancies").val(data.pregnancies);
             		$("#aborticide").val(data.aborticide);
             		$("#production").val(data.production);
//             		家族史
             		$("#cancerSel").val(data.cancer.substring(0,1));
             		if(data.cancer.substring(0,1)=='0'){
             			$("#cancer").hide();
             		}else{
             			$("#cancer").val(data.cancer.substring(1,data.cancer.length));	
             		}
             		$("#psychogenySel").val(data.psychogeny.substring(0,1));
             		if(data.psychogeny.substring(0,1)=='0'){
             			$("#psychogeny").hide();
             		}else{
             			$("#psychogeny").val(data.psychogeny.substring(1,data.psychogeny.length));	
             		}
             		$("#highBloodPressure").val(data.highBloodPressure);
             		$("#diabetes").val(data.diabetes);
             		$("#stroke").val(data.stroke);
             		$("#coronaryHeart").val(data.coronaryHeart);
             		$("#geneticDiseaseSel").val(data.geneticDisease.substring(0,1));
             		if(data.geneticDisease.substring(0,1)=='0'){
             			$("#geneticDisease").hide();
             		}else{
             			$("#geneticDisease").val(data.geneticDisease.substring(1,data.geneticDisease.length));	
             		}
             		$("#disabilitySel").val(data.disability.substring(0,1));
             		if(data.disability.substring(0,1)=='0'){
             			$("#disability").hide();
             		}else{
             			$("#disability").val(data.disability.substring(1,data.disability.length));	
             		}
             		//个人史
             		$("#birthPlace").val(data.birthPlace);
             		$("#educationDegree").val(data.educationDegree);
             		$("#birthPlace").val(data.birthPlace);
             		$("#localDiseaseSel").val(data.localDisease.substring(0,1));
             		if(data.localDisease.substring(0,1)=='0'){
             			$("#localDisease").hide();
             		}else{
             			$("#localDisease").val(data.localDisease.substring(1,data.localDisease.length));	
             		}
             		$("#economics").val(data.economics);
             		$("#profession").val(data.profession);
             		$("#sexualBehavior").val(data.sexualBehavior);
             		$("#presentIness").val(data.presentIness);
             		$("#id").val(data.id);
             		
             	}
             }
         }
     });
	});


function cancerOpt() {
	var cancerSel = $("#cancerSel").val();
	if(cancerSel==1){
	$("#cancer").show();
	}else{
		$("#cancer").hide();
	}
}

function psychogenyOpt(){
var psychogenySel = $("#psychogenySel").val();
	if(psychogenySel==1){
	$("#psychogeny").show();
	}else{
		$("#psychogeny").hide();
	}
}
function geneticDiseaseOpt(){
var geneticDiseaseSel = $("#geneticDiseaseSel").val();
	if(geneticDiseaseSel==1){
	$("#geneticDisease").show();
	}else{
		$("#geneticDisease").hide();
	}
}
function disabilityOpt(){
	var disabilitySel = $("#disabilitySel").val();
	if(disabilitySel==1){
	$("#disability").show();
	}else{
		$("#disability").hide();
	}
}
function toSave(){
	var id=$("#id").val();
	var $loadingToast = $('#loadingToast');
	if ($loadingToast.css('display') != 'none') {
		return;
	}
	$loadingToast.show();
	//既往史获取数据
	var bodyHealth=$("#bodyHealth").val();
	var bodyWeak=$("#bodyWeak").val();
	var wasSick=$("#wasSick").val();
	var bodyHealth=$("#bodyHealth").val();
	var majorTraumaSel=$("#majorTraumaSel").val();//重大外伤史
	var majorTrauma=$("#majorTrauma").val();
	if(majorTraumaSel==1){
		majorTrauma=majorTraumaSel+majorTrauma;
	}else{
		majorTrauma=majorTraumaSel;
	}
	var operationSel=$("#operationSel").val();
	var operation=$("#operation").val();
	if(operationSel==1){
		operation=operationSel+operation;
	}else{
		operation=operationSel;
	}
	var allergySel=$("#allergySel").val();
	var allergy=$("#allergy").val();
	if(allergySel==1){
		allergy=allergySel+allergy;
	}else{
		allergy=allergySel;
	}
	var timelyVaccination=$("#timelyVaccination").val();
	var transfusion=$("#transfusion").val();
	//婚育史
	var marriage=$("#marriage").val();
	var menophania=$("#menophania").val();
	var continueTime=$("#continueTime").val();
	var intervalTime=$("#intervalTime").val();
	var pausimenia=$("#pausimenia").val();
	var endMeniaTime=$("#endMeniaTime").val();
	var pregnancies=$("#pregnancies").val();
	var production=$("#production").val();
	var aborticide=$("#aborticide").val();
	//家族史
	var cancerSel=$("#cancerSel").val();
	var cancer=$("#cancer").val();
	if(cancerSel==1){
		cancer=cancerSel+cancer;
	}else{
		cancer=cancerSel;
	}
	var psychogenySel=$("#psychogenySel").val();
	var psychogeny=$("#psychogeny").val();
	if(psychogenySel==1){
		psychogeny=psychogenySel+psychogeny;
	}else{
		psychogeny=psychogenySel;
	}
	var highBloodPressure=$("#highBloodPressure").val();
	var diabetes=$("#diabetes").val();
	var stroke=$("#stroke").val();
	var coronaryHeart=$("#coronaryHeart").val();
	var geneticDiseaseSel=$("#geneticDiseaseSel").val();
	var geneticDisease=$("#geneticDisease").val();
	if(geneticDiseaseSel==1){
		geneticDisease=geneticDiseaseSel+geneticDisease;
	}else{
		geneticDisease=geneticDiseaseSel;
	}
	var disabilitySel=$("#disabilitySel").val();
	var disability=$("#disability").val();
	if(disabilitySel==1){
		disability=disabilitySel+disability;
	}else{
		disability=disabilitySel;
	}
	//个人史
	var birthPlace=$("#birthPlace").val();
	var educationDegree=$("#educationDegree").val();
	var localDiseaseSel=$("#localDiseaseSel").val();
	var localDisease=$("#localDisease").val();
	if(localDiseaseSel==1){
		localDisease=localDiseaseSel+localDisease;
	}else{
		localDisease=localDiseaseSel;
	}
	var economics=$("#economics").val();
	var profession=$("#profession").val();
	var sexualBehavior=$("#sexualBehavior").val();

	$.ajax({
         url: basePath+"diseaseHistory/toSave.spring",
         data: {
        	 bodyHealth:bodyHealth,
        	 bodyWeak:bodyWeak,
        	 wasSick:wasSick,
        	 majorTrauma:majorTrauma,
        	 operation:operation,
        	 allergy:allergy,
        	 timelyVaccination:timelyVaccination,
        	 transfusion:transfusion,
        	 marriage:marriage,
        	 menophania:menophania,
        	 continueTime:continueTime,
        	 intervalTime:intervalTime,
        	 pausimenia:pausimenia,
        	 endMeniaTime:endMeniaTime,
        	 pregnancies:pregnancies,
        	 production:production,
        	 aborticide:aborticide,
        	 cancer:cancer,
        	 psychogeny:psychogeny,
        	 highBloodPressure:highBloodPressure,
        	 diabetes:diabetes,
        	 stroke:stroke,
        	 coronaryHeart:coronaryHeart,
        	 geneticDisease:geneticDisease,
        	 disability:disability,
        	 birthPlace:birthPlace,
        	 educationDegree:educationDegree,
        	 localDisease:localDisease,
        	 economics:economics,
        	 profession:profession,
        	 sexualBehavior:sexualBehavior,
        	 id:id
         },
         type: "POST",
         dataType: 'json',
         cache: false,
         success: function (ret) {
             if(ret.content=="success"){
            	 setTimeout(function() {
		   				$loadingToast.hide();
		   				$("#toast").show();
		   				setTimeout(function() {
		   				 url=basePath+"jsp/caseHistory/caseHistoryList.jsp";
		   				 window.location.href=url;
				            $("#toast").hide();
						}, 800);}, 800);
             }else{
            	 alert("保存失败");
             }
         }
     });	
}